﻿@using System.IO
@inject DialogService DialogService

<div style="display: flex">
    <RadzenTree Change=@(args => selectedFile = args.Value.ToString()) Style="width: 50%; height: 300px">
        <RadzenTreeItem Text="Images" Expanded="true" Icon="">
            <RadzenTreeItem Text="radzen-blazor-components.png" Value="@($"/images/radzen-blazor-components.png")" />
            <RadzenTreeItem Text="radzen-blazor-studio.png" Value="@($"/images/radzen-blazor-studio.png")" />
        </RadzenTreeItem>
    </RadzenTree>
    <div style="width: 50%; padding: 16px; text-align: center;">
    @if (!string.IsNullOrEmpty(Path.GetExtension(selectedFile)))
    {
        <h4>Preview</h4>
        <RadzenImage Path=@(selectedFile) style="max-width: 100%" AlternateText="Selected image file preview" />
    }
    </div>
</div>

<div style="text-align: right">
    <RadzenButton Text="OK" Click=@OnOkClick />
    <RadzenButton Text="Cancel" Click=@OnCancelClick ButtonStyle="ButtonStyle.Secondary"  />
</div>
@code {
    string selectedFile;

    void OnCancelClick()
    {
        DialogService.Close(null);
    }

    void OnOkClick()
    {
        string result = null;

        if (selectedFile != null && !string.IsNullOrEmpty(Path.GetExtension(selectedFile)))
        {
            result = selectedFile;
        }

        DialogService.Close(result);
    }
}